#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
    static bool cmp(string a, string b) {
        return a + b > b + a;
    }
public:
    string largestNumber(vector<int>& nums) {
        vector<string> nums_str(nums.size());
        for (int i = 0; i < nums.size(); i++) {
            nums_str[i] = to_string(nums[i]);
        }
        sort(nums_str.begin(), nums_str.end(), cmp);
        if (nums_str[0] == "0") {
            return "0";
        }
        string output;
        for (string item : nums_str) {
            output += item;
        }
        return output;
    }
};

int main() {
    vector<int> input = {3, 30, 34, 5, 9};
    Solution solution;
    string output = solution.largestNumber(input);
    cout << output << endl;
    return 0;
}

